package manage

import (
	"azfirewall-gateway/data"
	"azfirewall-gateway/models"
	"azfirewall-gateway/service"
	"azfirewall-gateway/utils"
	"net/http"
)

func APIHandler(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	utils.MainLog.Debug("[请求路径："+r.URL.Path+"] 接收到请求参数：", params)
	if len(params["token"]) == 0 || params["token"][0] != data.CFG.ApiToken {
		utils.ProcessResponse(w, models.InvalidAuthority, "口令认证失败", nil)
		return
	}
	action := r.URL.Query().Get("action")
	switch action {
	case "SiteUpdateOrModify":
		service.SiteAM(r, w)
	case "QuerySites":
		service.SitesQuery(r, w)
	case "DeleteSite":
		service.SiteDelete(r, w)
	default:
		utils.ProcessResponse(w, models.InvalidParam, "无效的操作指令", nil)
		return
	}
}
func DefaultManageView(w http.ResponseWriter, r *http.Request) {
	utils.ProcessResponse(w, models.ForbidOperation, "不被接受的访问", nil)
}
